﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DHPlaySDK;
using Utility;
//
using DLLTest.OpertionClass;

namespace DLLTest
{
    public partial class frm_DataRecord : Form
    {
        public frm_DataRecord()
        {
            InitializeComponent();
        }

        private void frmDataRecord_Load(object sender, EventArgs e)
        {
            StringUtil.InitControlText(this);
            if (PanelOpertion.SelectedPanel == null)
            {
                return;
            }
            if (PanelOpertion.SelectedPanel.Tag != null)
            {
                #region 提取通道号,取出正在播放的通道号
                string[] panUD = PanelOpertion.SelectedPanel.Tag.ToString().Split(',');
                txtchannNo.Text = panUD[5].ToString();//通道号                   
                #endregion
            }
        }
       
        /// <summary>
        /// 开始录像按钮按下处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStartRecord_Click(object sender, EventArgs e)
        {
            if (txtchannNo.Text == "")
            {
                MessageBox.Show("请选择正在播放的通道","提示");
                return;
            } 
            string strtemp = Application.StartupPath + @".\dhVedio\DH_" + DateTime.Now.ToString("yyyyMMddHHmmss");
            if (cmbDataType.SelectedIndex == 0)
            {               
                if (strtemp.Length > 2)
                {
                    //开始录像
                    if (DHPlay.DHStartDataRecord(Convert.ToInt32(txtchannNo.Text), strtemp, cmbDataType.SelectedIndex))
                    {
                        MessageBox.Show("开始数据流保存成功!", "提示:");
                        //MessageBox.Show(strtemp, "提示:");
                    }
                    else
                    {
                        MessageBox.Show("开始数据流保存失败!", "提示:");
                    }                   
                }
            }
            //else if (cmbDataType.SelectedIndex == 1)//如果以AVI文件格式保存，会提示错误。
            //{
            //    //string strtempAVI = Application.StartupPath + @".\dhVedio\DH_" + DateTime.Now.ToString("yyyyMMddHHmmss");
            //    if (strtemp.Length > 2)
            //    {
            //        //开始录像
            //        if (DHPlay.DHStartDataRecord(Convert.ToInt32(txtchannNo.Text), strtemp, cmbDataType.SelectedIndex))
            //        {
            //            MessageBox.Show("开始AVI保存成功!", "提示:");
            //            //MessageBox.Show(strtemp, "提示:");
            //        }
            //        else
            //        {
            //            MessageBox.Show("开始AVI保存失败!", "提示:");
            //        }
            //    }
            //}
            else 
            {
                MessageBox.Show("请选择保存格式");
            }
        }
        /// <summary>
        /// 停止录像按钮按下处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStopRecord_Click(object sender, EventArgs e)
        {
            if (txtchannNo.Text == "")
                return;          
               //根据通道号停止录像
                if (DHPlay.DHStopDataRecord(Convert.ToInt32(txtchannNo.Text)) == true)
                {
                    MessageBox.Show("停止数据流保存成功!", "提示:");
                }
                else { MessageBox.Show("停止数据流保存失败!", "提示:"); 
                }
           
        }
    }
}